import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import UserLayout from '@/layout/UserLayout'
import BasicLayout from '@/layout/BasicLayout'

const routes = [
  {
    path: '/',
    component: UserLayout,
    children: [
      {
        path: '/',
        redirect: '/login',
      },
      {
        path: '/login',
        meta: {
          title: '登录'
        },
        component: () => import('@/views/login')
      },
    ]
  },
  {
    path: '/',
    component: BasicLayout,
    children: [
      {
        path: '/',
        redirect: '/resource',
      },
      {
        path: '/resource',
        meta: {
          title: '资源库'
        },
        component: () => import('@/views/home/Resource')
      },
      {
        path: '/authapplice',
        meta: {
          title: '授权申请'
        },
        component: () => import('@/views/home/Authapplice')
      },
      {
        path: '/authapproval',
        meta: {
          title: '授权审批'
        },
        component: () => import('@/views/home/Authapproval')
      },
      {
        path: '/usermanagement',
        meta: {
          title: '用户管理'
        },
        component: () => import('@/views/home/Usermanagement')
      },
      {
        path: '/systemset',
        meta: {
          title: '系统管理'
        },
        component: () => import('@/views/home/Systemset')
      },
    ],
  },
];

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  routes
});

export default router